package com.android.tetris;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

/**
 * Hien thi danh sach 5 nguoi choi co ket qua cao nhat
 * 
 * @author Administrator
 * 
 */
public class HighScores extends Activity {

	// TextViews for the scores
	private TextView hs1, hs2, hs3, hs4, hs5;
	
	// TextViews for the dates
	private TextView hs1d, hs2d, hs3d, hs4d, hs5d;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		// Saved values
		SharedPreferences highScores;

		// Assign layouts
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.highscores);

		// Assign textViews
		hs1 = (TextView) findViewById(R.id.textViewHighScore1);
		hs2 = (TextView) findViewById(R.id.textViewHighScore2);
		hs3 = (TextView) findViewById(R.id.textViewHighScore3);
		hs4 = (TextView) findViewById(R.id.textViewHighScore4);
		hs5 = (TextView) findViewById(R.id.textViewHighScore5);

		hs1d = (TextView) findViewById(R.id.textViewHighScore1Date);
		hs2d = (TextView) findViewById(R.id.textViewHighScore2Date);
		hs3d = (TextView) findViewById(R.id.textViewHighScore3Date);
		hs4d = (TextView) findViewById(R.id.textViewHighScore4Date);
		hs5d = (TextView) findViewById(R.id.textViewHighScore5Date);

		// Load high scores. Only write if they exist
		// If none exists, display "No high scores"
		highScores = getSharedPreferences("highScores", 0);
		
		if (highScores.getInt("hScore1", 0) > 0) {
			hs1.setText(getResources().getString(R.string.first) + ": "
					+ Integer.toString(highScores.getInt("hScore1", 0)) + " điểm");
			hs1d.setText(highScores.getString("hScore1Date", " "));
		} else {
			hs1d.setText(getResources().getString(R.string.nohscores));
		}
		
		if (highScores.getInt("hScore2", 0) > 0) {
			hs2.setText(getResources().getString(R.string.second) + ": "
					+ Integer.toString(highScores.getInt("hScore2", 0)) + " điểm");
			hs2d.setText(highScores.getString("hScore2Date", " "));
		}
		
		if (highScores.getInt("hScore3", 0) > 0) {
			hs3.setText(getResources().getString(R.string.third) + ": "
					+ Integer.toString(highScores.getInt("hScore3", 0)) + " điểm");
			hs3d.setText(highScores.getString("hScore3Date", " "));
		}
		
		if (highScores.getInt("hScore4", 0) > 0) {
			hs4.setText(getResources().getString(R.string.four) + ": "
					+ Integer.toString(highScores.getInt("hScore4", 0)) + " điểm");
			hs4d.setText(highScores.getString("hScore4Date", " "));
		}
		
		if (highScores.getInt("hScore5", 0) > 0) {
			hs5.setText(getResources().getString(R.string.five) + ": "
					+ Integer.toString(highScores.getInt("hScore5", 0)) + " điểm");
			hs5d.setText(highScores.getString("hScore5Date", " "));
		}
	}
}
